﻿using System;

namespace h10
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] bills = new[] {5,5,10,20};
            Solution s=new Solution();
            Console.WriteLine(s.LemonadeChange(bills));
            
        }
    }
    
    public class Solution
    {
        public int fives = 0;
        public int tens = 0;
        public bool LemonadeChange(int[] bills)
        {
            bool result = true;
            foreach (int bill in bills)
            {
                switch (bill)
                {
                    case 5:
                        result=result&CheakFive();
                        break;
                    case 10:
                        result=result&CheckTen();
                        break;
                    case 20:
                        result=result&CheakTewenty();
                        break;
                    default:
                        break;
                }
            }
            
            

            return result;
        }

        public bool CheakFive()
        {
            this.fives += 1;
            return true;
        }

        public bool CheckTen()
        {
            if (this.fives > 0)
            {
                this.fives -= 1;
                this.tens += 1;
                return true;
            }
            else
            {
                return false;
            }
        }

        public bool CheakTewenty()
        {
            if (this.fives <= 0)
            {
                return false;
            }
            else
            {
                if (this.tens > 0)
                {
                    if (this.fives > 0)
                    {
                        this.tens -= 1;
                        this.fives -= 1;
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                    
                }
                else
                {
                    if (this.fives >= 3)
                    {
                        this.fives -= 3;
                        return true;
                    }

                    return false;
                }

                // return false;
            }
        }
    }
}